package com.iamteer.cupband;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class RemoteInteractActivity extends Activity {

    private TextView tvName;
    private TextView tvDate;
    private ImageView ivBack;
    private ProgressBar pbResult;
    private FrameLayout resultFrameLayout;
    private TextView tvResultProgressBar;
    private Button btnRemind;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remote_interact);


        ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowHomeEnabled(true);
        ActionBar.LayoutParams lp =new ActionBar.LayoutParams(
                ActionBar.LayoutParams.MATCH_PARENT,
                ActionBar.LayoutParams.MATCH_PARENT,
                Gravity.CENTER);
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View titleView = inflater.inflate(R.layout.activity_remote_interact_title, null);
        actionBar.setCustomView(titleView, lp);

        actionBar.setDisplayShowHomeEnabled(false);//去掉导航
        actionBar.setDisplayShowTitleEnabled(false);//去掉标题
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setDisplayShowCustomEnabled(true);

        ivBack = (ImageView) actionBar.getCustomView().findViewById(R.id.ivBack);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        tvDate = (TextView) findViewById(R.id.tvDate);
        int month, day, weekday;
        final Date CurrentDate;
        final Calendar CurrentCalendar;
        CurrentCalendar = Calendar.getInstance(Locale.CHINA);
        CurrentDate = new Date();
        CurrentCalendar.setTime(CurrentDate);

        month = CurrentCalendar.get(Calendar.MONTH) + 1;
        day = CurrentCalendar.get(Calendar.DAY_OF_MONTH);
        weekday = CurrentCalendar.get(Calendar.DAY_OF_WEEK);

        tvDate.setText(String.format("%02d月%02d日 星期", month, day)+ ObserveFragment.WeekDayString[weekday - 1]);

        tvName = (TextView) findViewById(R.id.tvName);
        TextPaint tp = tvName.getPaint();
        tp.setFakeBoldText(true);

        pbResult = (ProgressBar) findViewById(R.id.pbResult);
        resultFrameLayout = (FrameLayout) findViewById(R.id.resultFrameLayout);
        tvResultProgressBar = (TextView) findViewById(R.id.tvResultProgressBar);
        btnRemind = (Button) findViewById(R.id.btnRemind);


        pbResult.setMax(8);
        pbResult.setProgress(4);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        int ScreenWidth = dm.widthPixels;

        int position = (ScreenWidth - 168) / 8 * 4;
        setMargins(resultFrameLayout, position, 0, 0, 0);
        tvResultProgressBar.setText(Integer.toString(4));


        btnRemind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(RemoteInteractActivity.this, "提醒已发出", Toast.LENGTH_SHORT).show();
            }
        });

    }
    public static void setMargins(View view, int left, int top, int right, int bottom) {
        if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
            p.setMargins(left, top, right, bottom);
            view.requestLayout();
        }
    }
}
